import matplotlib.pyplot as plt
import numpy as np
from test3 import create_polar_system

# 创建极坐标系
fig, ax = create_polar_system(r_range=(0, 5))

# 生成θ值（避开cosθ=0的点）
theta1 = np.linspace(0.01, np.pi/2 - 0.01, 100)      # 第一象限
theta2 = np.linspace(3*np.pi/2 + 0.01, 2*np.pi - 0.01, 100)  # 第四象限
theta_values2 = np.concatenate([theta1, theta2])

# 点(a,0)
a = 2

# 计算ρ值：ρ = a / cosθ
rho_values2 = a / np.cos(theta_values2)

# 过滤掉ρ值过大的点（保持图形清晰）
mask = (rho_values2 <= 5) & (rho_values2 >= 0)
theta_values2 = theta_values2[mask]
rho_values2 = rho_values2[mask]

ax.plot(theta_values2, rho_values2, 'b-', linewidth=2, label='垂直极轴: ρ cos θ = 2')

# 标记点M(a,0) = (2,0)
ax.plot(0, a, 'bo', markersize=8, label='点M(2,0)')

# 添加图例和装饰
ax.legend(loc='upper right', bbox_to_anchor=(1.15, 1.15))

plt.tight_layout()
plt.show()
